package edu.uc.dao;

import java.io.IOException;
import java.util.HashMap;

import edu.uc.dto.User;

/**
 * Class = UserProviderStub implements the IUserDAO interface
 * 
 * @author Ckorczyk1
 *
 */

public class UserProviderStub implements IUserDAO{


	/**
	 * Method Save 
	 * 
	 * @param = user
	 * @throws exception if username and password  are blank or null.  
	 * 
	 * process normally if username and password are completed.
	 */
	@Override
	public void save(User user) throws Exception {
		// TODO Auto-generated method stub

		//Should process normally if the username and password are complete

		//check to see if the username is null
		if(user.getUsername().equals(null)){
			throw new IOException("Some required files are missing");
		}
		//Check to see if the password is null
		if(user.getPassword().equals(null)){
			throw new IOException("Some required files are missing");
		}




	}

	/**
	 * method fetch
	 * 
	 * @param = String username
	 * @throws exception in other circumstances
	 * 
	 * create and return a new User object if the username is Caz
	 *  
	 */
	@Override
	public User fetch(String username) throws Exception {
		// TODO Auto-generated method stub

		//If the username is correct then populate the hashmap
		if(username == "Caz"){
			User user= new User();

			user.setUsername("Caz");
			user.setPassword("Cha5e5Cars");
			user.setFirstName("Caz");
			user.setLastName("Dolowicz");
			user.setPrefix("Mr.");
			user.setPhoneNumber("(513)123-4567");

			return user;

		}
		//thow an exception if the username is incorrect
		else{
			throw new IOException("Wrong username was entered");
		}	
	}

	/**
	 * method hashMap FetchAll
	 * 
	 * @return HashMap<String, User> with a single User object
	 */
	@Override
	public HashMap<String, User> fetchAll() {
		// TODO Auto-generated method stub

		//create and populate hashmap
		HashMap<String,User> hash = new HashMap<String,User>();
		User user = new User();
		hash.put("Caz", user);

		user.setUsername("Caz");
		user.setPassword("Cha5e5Cars");
		user.setFirstName("Caz");
		user.setLastName("Dolowicz");
		user.setPrefix("Mr.");
		user.setPhoneNumber("(513)123-4567");



		return hash;
		//return null;
	}

}
